const app = getApp()
const util = require('../../../../utils/util.js')
import {list} from "../../../../api/ad"
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    showUnReadNum:{
      type:String,
      value:0
    },
    name:{
      type:String
    },
    avatar:{
      type:String
    },
    userInfo:{
      type:Object
    },
  },
  
  /**
   * 组件的初始数据
   */
  data: {
    token:null,
    adForm:[]
  },

  /**
   * 组件的方法列表
   */
  pageLifetimes: {
    show: function() {
      // 页面被展示
      this.adClick()
      this.data.token = app.globalData.token
      this.setData({
        token:this.data.token
      })
    },
  },
  methods: {
    tohome:function(){
        wx.navigateTo({
          url: '/pages/member/follow/dynamic/index?id=' + this.data.userInfo.id,
        })
        },
        dataClick(){
          wx.navigateTo({
            url: '/pages/member/personInfo/index',
          })
        },
    adClick(){
      var _this = this
      list({adPositionId:10}).then(res=>{
        console.log(res)
        res.data.data.forEach(function(item){
          item.thumbnail = util.thumbnail(item.thumbnail,710,118)
        })
        _this.data.adForm = res.data.data
        _this.setData({
          adForm:_this.data.adForm
        })
      })
    },
    personinfoClick(){
      if(util.isNull(app.globalData.token)){
        wx.navigateTo({
          url: '/pages/login/index',
        })
      }else{
        wx.navigateTo({
          url: '/pages/member/personInfo/index',
        })
      }
    },
    tofollow(e){
      if(util.isNull(app.globalData.token)){
        wx.navigateTo({
          url: '/pages/login/index',
        })
      }else{
        wx.navigateTo({
          url: '/pages/member/follow/index?id=' + e.currentTarget.dataset.index
        })
      }
    },
    ceshiClick(data){
      if (data.currentTarget.dataset.type == 0) {
        wx.navigateTo({
          url: '/pages/shop/productDetail/productDetail?productId=' + data.currentTarget.dataset.id
        })
      } else if (data.currentTarget.dataset.type == 2) {
        wx.navigateTo({
          url: '/pages/hotspot/hotspot/index?id=' + data.currentTarget.dataset.id,
        })
      } else if (data.currentTarget.dataset.type == 3) {
        wx.navigateTo({
          url: '/pages/discovery/details/details?id=' + data.currentTarget.dataset.id
        })
      } else if (data.currentTarget.dataset.type == 4) {
        wx.navigateTo({
          url: '/pages/travel/travel/index?scenicSpotId=' + data.currentTarget.dataset.id
        })
      } else if (data.currentTarget.dataset.type == 5) {
        wx.navigateTo({
          url: '/pages/shop/shopDetail/index?shopId=' + data.currentTarget.dataset.id + '&mchId=10202' 
        })
      } else if (data.currentTarget.dataset.type == 6) {
        wx.navigateTo({
          url: '/pages/cook/kitchenBrigade/kitchenBrigade?id=' + data.currentTarget.dataset.id + '&mchId=10202'
        })
      } else if (data.currentTarget.dataset.type == 7) {
        wx.navigateTo({
          url: '/pages/shop/shopDetail/index?shopId=' + data.currentTarget.dataset.id + '&mchId=10202' 
        })
      } else if (data.currentTarget.dataset.type == 8) {
        wx.navigateTo({
          url: '/pages/member/coupon/index',
        })
      }else if (data.currentTarget.dataset.type == 9) {
        wx.navigateTo({
          url: '/pages/index/wxPage/wxPage?id='+data.currentTarget.dataset.id 
        })
      } else if (data.currentTarget.dataset.type == 12) {

      }
    },
    loginClick(){
      var _this = this
      console.log(app.globalData.token)
      if(util.isNull(app.globalData.token)){
        wx.navigateTo({
          url: '/pages/login/index',
        })
      }
  
  
    }
  }
})
